package com.homegoods.videomodule.ui.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.resource.SpacesItemDecoration;
import com.homegoods.resource.util.Utils;
import com.homegoods.videomodule.R;
import com.homegoods.videomodule.model.LiveShowModel;
import com.homegoods.videomodule.presenter.LiveShowPresenter;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.base.KRefreshListActivity;
import com.kedll.library.databinding.GeneralIncludeActionbarAndListBinding;

/**
 * @author QiQi
 * @ClassName: LiveShowListActivity
 * @date 2018/10/25
 * @description
 */
@Route(path = ARouterPath.PATH_COMMUNITY_LIVE)
public class LiveShowListActivity extends KRefreshListActivity<GeneralIncludeActionbarAndListBinding, LiveShowPresenter> {
    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        list.setClipToPadding(true);
        list.addItemDecoration(new SpacesItemDecoration(2, 8));
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return Utils.getGridLayoutManager(this, adapter, 2);
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        adapter.setOnItemClickListener((MultiTypeAdapter.OnItemClickListener<LiveShowModel>) (v, iItem) -> {
            if (Build.VERSION.SDK_INT < 16) {
                ARouter.getInstance()
                        .build(ARouterPath.PATH_LIVE_SHOW)
                        .navigation();
            } else {

                ImageView imageView = v.findViewById(R.id.iv_img);
                int[] loc = new int[2];
                imageView.getLocationInWindow(loc);

                ActivityOptionsCompat compat = ActivityOptionsCompat.makeScaleUpAnimation(imageView, loc[0], loc[1], 0, 0);

                ARouter.getInstance()
                        .build(ARouterPath.PATH_LIVE_SHOW)
                        .withObject("data", iItem.getData())
                        .withOptionsCompat(compat)
                        .navigation();

            }
        });
    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("社区直播");
        setTopRightButton("", R.mipmap.icon_msg, v -> ARouter.getInstance()
                .build(ARouterPath.PATH_MESSAGE_LIST)
                .navigation());
    }

    @Override
    protected LiveShowPresenter getPresenter() {
        return new LiveShowPresenter(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.general_include_actionbar_and_list;
    }
}
